import java.lang.reflect.Method;

/**
 * 字节码反编译:
 * public class TestV3 {
 *   public TestV3();
 *     Code:
 *        0: aload_0
 *        1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 *        4: return
 *
 *   public static void target(int);
 *     Code:
 *        0: return
 *
 *   public static void main(java.lang.String[]) throws java.lang.Exception;
 *     Code:
 *        0: ldc           #2                  // String TestV3
 *        2: invokestatic  #3                  // Method java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
 *        5: astore_1
 *        6: aload_1
 *        7: ldc           #4                  // String target
 *        9: iconst_1
 *       10: anewarray     #5                  // class java/lang/Class
 *       13: dup
 *       14: iconst_0
 *       15: getstatic     #6                  // Field java/lang/Integer.TYPE:Ljava/lang/Class;
 *       18: aastore
 *       19: invokevirtual #7                  // Method java/lang/Class.getMethod:(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
 *       22: astore_2
 *       23: invokestatic  #8                  // Method java/lang/System.currentTimeMillis:()J
 *       26: lstore_3
 *       27: iconst_1
 *       28: istore        5
 *       30: iload         5
 *       32: ldc           #9                  // int 2000000000
 *       34: if_icmpgt     88
 *       37: iload         5
 *       39: ldc           #10                 // int 100000000
 *       41: irem
 *       42: ifne          63
 *       45: invokestatic  #8                  // Method java/lang/System.currentTimeMillis:()J
 *       48: lstore        6
 *       50: getstatic     #11                 // Field java/lang/System.out:Ljava/io/PrintStream;
 *       53: lload         6
 *       55: lload_3
 *       56: lsub
 *       57: invokevirtual #12                 // Method java/io/PrintStream.println:(J)V
 *       60: lload         6
 *       62: lstore_3
 *       63: aload_2
 *       64: aconst_null
 *       65: iconst_1
 *       66: anewarray     #13                 // class java/lang/Object
 *       69: dup
 *       70: iconst_0
 *       71: sipush        1024
 *       74: invokestatic  #14                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
 *       77: aastore
 *       78: invokevirtual #15                 // Method java/lang/reflect/Method.invoke:(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
 *       81: pop
 *       82: iinc          5, 1
 *       85: goto          30
 *       88: return
 * }
 */
public class TestV3 {

    public static void target(int i) {
        // 空方法
    }

    public static void main(String[] args) throws Exception {
        //反射调用V1
        Class<?> klass = Class.forName("TestV3");
        Method method = klass.getMethod("target", int.class);
        long current = System.currentTimeMillis();
        for (int i = 1; i <= 2_000_000_000; i++) {
            if (i % 100_000_000 == 0) {
                long temp = System.currentTimeMillis();
                System.out.println(temp - current);
                current = temp;
            }
            //反射调用被内联
            method.invoke(null, 1024);
        }
    }
}